<!-- this.$emit用于子组件向父组件传递自定义事件 -->
<template>
  <div class="father">
    <h3>父组件，</h3>
    <h4>我的车：{{ car }}</h4>
    <h4>儿子给的玩具：{{ toy }}</h4>
    <Child :car="car"></Child>
  </div>
</template>

<script setup lang="ts" name="Father">
import Child from './Child.vue'
import emitter from './emitter'
import { ref,onBeforeUnmount } from 'vue'
// 数据
const car = ref('奔驰')
const toy = ref()
emitter.on('getToy', (value) => {
  console.log('我收到了来自子组件的消息', value)
  toy.value = value
})
onBeforeUnmount(() => {
  emitter.off('getToy')
})
</script>
